package com.company.hrmadmin.modules.controller;

import com.company.hrmadmin.common.constant.Result;
import com.company.hrmadmin.modules.domain.Department;
import com.company.hrmadmin.modules.service.DepartmentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 部门
 *
 * @author Song, Wei
 * Date: 2022/4/1 11:28
 */
@Slf4j
@RestController
@RequestMapping("/dep")
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

    @RequestMapping(path = "/list", method = RequestMethod.GET)
    public Result<?> getDepList() {
        log.info("获取所有顶级部门");
        return Result.success(departmentService.getTopDepList());
    }

    @RequestMapping(path = "/list/{depId}", method = RequestMethod.GET)
    public Result<Department> getDepParent(@PathVariable("depId") Integer depId) {
        log.info("获取上级直系部门，参数：{}", depId);
        return Result.success(departmentService.getParentDep(depId));
    }

    @RequestMapping(path = "/list/child/{depId}", method = RequestMethod.GET)
    public Result<List<Department>> getDepChild(@PathVariable("depId") Integer depId) {
        log.info("获取下级直系部门，参数：{}", depId);
        return Result.success(departmentService.getChildrenDepList(depId));
    }

    @RequestMapping(path = "/list/rec/{depId}", method = RequestMethod.GET)
    public Result<List<Department>> getDepListById(@PathVariable("depId") Integer depId) {
        log.info("获取该部门所有下级部门，参数：{}", depId);
        return Result.success(departmentService.getDepRecListById(depId));
    }

    @RequestMapping(path = "/list/tree", method = RequestMethod.GET)
    public Result<List<Department>> getDepTree() {
        log.info("获取部门树形列表");
        return Result.success(departmentService.getDepTreeList());
    }

}
